<template lang="pug">
  ToteaForm(v-model="form" :model="form" :schema="schema" :rules="rules" action="post" @comfirm="onComfirm")
</template>

<script>
import toteaTypes from "totea/types";

const group = new toteaTypes.ToteaGroup({
  ...toteaTypes.baseMixin,
  name: toteaTypes.shortText("标题").required(),
  summary: toteaTypes.text("简介").required(),
  detail: toteaTypes.longText("文章详情").required(),
  category: toteaTypes.ref("category", "分类").required().formType("category"),
  auther: toteaTypes
    .ref("admin", "作者")
    .refFilter({ role: 1 }, "只有文章发布员才能新建文章")
    .forbidUpdate()
    .required(),
  keyword: toteaTypes.array(String, "关键词"),
  tag: toteaTypes.ids("tag", "标签").max(2),
  readNum: toteaTypes.int("阅读数").forbidCreate().default(0),
  starNum: toteaTypes.int("点赞数").forbidCreate().default(0),
  hot: toteaTypes
    .int("文章热度")
    .computed((doc) => doc.starNum * 5 + doc.readNum),
  isForbid: toteaTypes.boolean("已禁用").forbidCreate().default(false),
  top: toteaTypes.int("置顶等级").max(10).default(0),
  email: toteaTypes.email(),
});

const rules = group.toElementRules();

export default {
  data() {
    return {
      form: {},
      schema: group.createFormSchema,
      rules,
    };
  },
  methods: {
    handleChange() {
      console.log("handleChange");
    },
    onComfirm(value) {
      console.log("comfirm", value);
    },
  },
  created() {},
};
</script>
